class: center, middle, inverse, title-slide .title[ # Bivariate Tables ] .subtitle[ ## EDP 613 ] .author[ ### Week 9 ] --- <script> function resizeIframe(obj) { obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; } </script>
# <span style='color:#bff4ee;'>A Note About The Slides</span> Currently the equations may not show up properly in Firefox. Other browsers such as Chrome and Safari do appear to render them correctly. --- # Terms -- **bivariate** - Doing something with two variables -- **bivariate analysis** -- >- *Formally*: A statistical method to detect and describe the relationship between two nominal or ordinal variables (typically independent and dependent variables) -- >- *Nutshell*: Finding out if and how two variables are related to each other -- **cross-tabulation** -- >- *Formally*: A tool for analyzing the relationship between two or more nominal or ordinal variables -- >- *Nutshell*: A data table to compare the values between two variables -- >- *Note*: A good approach when establishing "control" variables --- # Bivariate Tables -- <img src="img/bivaraite_table.png" width="40%" style="display: block; margin: auto;" /> .footnote[*totals* are also known as *marginals*] --- # Creating a Cross-Tabulation Using Raw Data -- >- Column totals: Add across columns -- >- Row totals: Add across rows --- # Example of Cross-Tabulation Using Raw Data <table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;"> <caption><b>Views on Candy Corn</b></caption> <thead> <tr><th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; padding-right: 4px; padding-left: 4px; background-color: #212121 !important;" colspan="4"><div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">Sentiment</div></th></tr> <tr> <th style="text-align:center;background-color: #212121 !important;"> </th> <th style="text-align:center;background-color: #212121 !important;"> Delicious </th> <th style="text-align:center;background-color: #212121 !important;"> Disgusting </th> <th style="text-align:center;background-color: #212121 !important;"> </th> </tr> </thead> <tbody> <tr> <td style="text-align:center;width: 10em; font-weight: bold;"> Yes </td> <td style="text-align:center;width: 10em; "> 4 </td> <td style="text-align:center;width: 10em; "> 7 </td> <td style="text-align:center;width: 10em; "> 11 </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> No </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 6 </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 9 </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 15 </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;"> </td> <td style="text-align:center;width: 10em; "> 10 </td> <td style="text-align:center;width: 10em; "> 16 </td> <td style="text-align:center;width: 10em; "> 26 </td> </tr> </tbody> </table> --- # Creating a Cross-Tabulation Using Percents -- .pull-left[ <span style='color:#e5a8be;'><i>Column</i></span> <i>percentages</i> :<br><br> Use column totals as a denominator of the row values. ] -- .pull-right[ <span style='color:#61b2e3;'><i>Row</i></span> <i>percentages</i> :<br><br> Use column totals as a denominator of the row values. ] -- <br> <center> <i>Note</i>: Percentages are typically given for the independent variable. </center> --- # Example of Cross-Tabulation Using Percents <table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;"> <caption><b>Views on Candy Corn</b></caption> <thead> <tr><th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; padding-right: 4px; padding-left: 4px; background-color: #212121 !important;" colspan="4"><div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">Sentiment</div></th></tr> <tr> <th style="text-align:center;background-color: #212121 !important;"> </th> <th style="text-align:center;background-color: #212121 !important;"> Delicious </th> <th style="text-align:center;background-color: #212121 !important;"> Disgusting </th> <th style="text-align:center;background-color: #212121 !important;"> </th> </tr> </thead> <tbody> <tr> <td style="text-align:center;width: 10em; font-weight: bold;"> Yes </td> <td style="text-align:center;width: 10em; "> 40.00% (4) </td> <td style="text-align:center;width: 10em; "> 43.75% (7) </td> <td style="text-align:center;width: 10em; "> 42.30% (11) </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> No </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 60.00% (6) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 56.25% (9) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 57.69% (15) </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;"> <i>N</i> </td> <td style="text-align:center;width: 10em; "> (10) </td> <td style="text-align:center;width: 10em; "> (16) </td> <td style="text-align:center;width: 10em; "> (26) </td> </tr> </tbody> </table> -- <center> That is a <b>contingency table</b> </center> -- <br> <center> Specifically a <b>2 x 2 contingency table</b> </center> --- # Why Do We Care? Well we use them if we want to -- - *partition* the dependent and independent variables -- - detect if a relationship *exists* between the dependent and independent variables -- - measure how *strong* a relationship may be (known as a *measure of association*) -- - determine the *direction* of a relationship --- # This Way or That Way The direction of a relationship can be -- .pull-left[ **positive** if the dependent and independent both go in the same direction up or down ] -- .pull-right[ **negative** if the dependent and independent go in opposite directions ] --- # Example of a Positive Relationship <table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;"> <caption><b>Health Condition by SES</b></caption> <thead> <tr><th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; padding-right: 4px; padding-left: 4px; background-color: #212121 !important;" colspan="4"><div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">Sentiment</div></th></tr> <tr> <th style="text-align:center;background-color: #212121 !important;"> </th> <th style="text-align:center;background-color: #212121 !important;"> Low </th> <th style="text-align:center;background-color: #212121 !important;"> Middle </th> <th style="text-align:center;background-color: #212121 !important;"> High </th> </tr> </thead> <tbody> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> Poor </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 39% (15) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 12% (32) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 9% (18) </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> Fair </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 36% (14) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 45% (114) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 28% (57) </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> Good </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 25% (10) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 43% (109) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 63% (127) </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> <i>N</i> </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> (39) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> (254) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> (202) </td> </tr> </tbody> </table> *Source: General Social Survey: 1987-1992* --- # Example of a Negative Relationship <table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;"> <caption><b>Frequency of Trauma by SES</b></caption> <thead> <tr><th style="border-bottom:hidden;padding-bottom:0; padding-left:3px;padding-right:3px;text-align: center; padding-right: 4px; padding-left: 4px; background-color: #212121 !important;" colspan="4"><div style="border-bottom: 1px solid #ddd; padding-bottom: 5px; ">Sentiment</div></th></tr> <tr> <th style="text-align:center;background-color: #212121 !important;"> </th> <th style="text-align:center;background-color: #212121 !important;"> Low </th> <th style="text-align:center;background-color: #212121 !important;"> Middle </th> <th style="text-align:center;background-color: #212121 !important;"> High </th> </tr> </thead> <tbody> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> Poor </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 31% (15) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 41% (90) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 48% (86) </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> Fair </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 22% (10) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 42% (92) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 20% (36) </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> Good </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 47% (23) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 17% (38) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 32% (58) </td> </tr> <tr> <td style="text-align:center;width: 10em; font-weight: bold;background-color: #212121 !important;"> <i>N</i> </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> (48) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> (220) </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> (180) </td> </tr> </tbody> </table> *Source: General Social Survey: 1987-1992* --- # Other Explanations -- <center>hours studying & grades</center> -- <br> <center>partying & assessments</center> -- <br> <center>sleep & performance</center> -- <br> <center>Color of your car & how well you do in EDP 613</center> -- <br> <center>.</center> -- <br> <center>.</center> --- # Elaborate -- - A **control variable** is a special type of variable that doesn't change. We can use it to compare the possible effects of a treatment. -- - **Elaboration** is a specific type of bivariate relationship where control variables are introduced. --- # Testing for an intervening relationship - **Intervening variable** - A control variable that follows an independent variable but precedes the dependent variable in a causal sequence -- - **Intervening relationships** - The control variable intervenes between the independent and dependent variables --- # Example: Examining two variables before considering a third one - <span style='color:#78c4a9;'>independent</span> variable: Attending weekday parties -- - <span style='color:#e5a8be;'>dependent</span> variable: Grades -- - <span style='color:#b5caa8;'>intervening</span></span> variable (maybe): Hours studying --- # Example - <span style='color:#78c4a9;'>independent</span> variable: Sale of ice cream -- - <span style='color:#e5a8be;'>dependent</span> variable: Number of outdoor crimes -- - <span style='color:#b5caa8;'>intervening</span></span> variable (maybe): Outdoor temperature --- ### Testing for a spurious relationship - **Spurious relationships** - Both the independent variable and the dependent variable are NOT -- 1. not causally linked -- 2. influenced by some third variable -- 3. explained by a control variable -- - **Nonspurious relationships** - Both the independent variable and the dependent variable - cannot by explained by a control variable --- # Example - <span style='color:#78c4a9;'>independent</span> variable: Number of firefighters at the scene of a crime -- - <span style='color:#e5a8be;'>dependent</span> variable: Property damage -- - Possible cause prior to the control variable: Size of the fire --- # Elaborate -- - A **control variable** is a special type of variable that doesn't change. We can use it to compare the possible effects of a treatment. -- - **Elaboration** is a specific type of bivariate relationship where control variables are introduced. --- # Testing Elaboration tests - are useless on relationships that have been determined like - *causal* : At least one variable is found to directly effect another -- - include relationships that are - *spurious* : Both an independent and dependent variable are influenced by some third party variable. If the third variable is unknown, it may appear that there is a causal link when there actually isn't one. -- - *intervening* : A control variable that comes after an independent variable but is before the dependent variable in a causal chain -- - *conditional* : An independent variable’s effect on the dependent variable depends something within a control variable --- # Testing for a control relationship <center> <b>control relationship</b> - An independent variable’s effect on the dependent variable depends on, or is conditioned by, a category of a control variable </center> -- <br> <center> <i>Note</i>: The relationship between the independent and dependent variables will change according to the different conditions (or categories) of the control variable </center> --- # Example: Examining two variables before considering a control - <span style='color:#78c4a9;'>independent</span> variable: Number of toys owned -- - <span style='color:#e5a8be;'>dependent</span> variable: Hours spent playing with toys -- - <span style='color:#BDA8CA;'>conditional</span></span> variable (maybe): SES --- # Goals of Elaboration -- 1. *to* test for spurious relationships -- 2. *to* clear up the causal sequence of bivariate relationships by finding possible intervening variables -- 3. *to* specify the different conditions under which the original bivariate relationship might hold --- ## That's it. Take a break before our R session! <br> <br> <img src="img/sc.png" width="80%" style="display: block; margin: auto;" /> .footnote[See more ridiculous correlations at [spurious correlations](https://www.tylervigen.com/spurious-correlations)]